#include <vector>
#include <set>
#include <iostream>
#include <unordered_map>

using namespace std;

int gcd(int a, int b) {
    while (b != 0)  {
        int t = b;
        b = a % b;
        a = t;
    }
    return a;
}

void rotate(vector<int>& nums, int k) {
    int n = nums.size();
    k = k % n;
    int count = gcd(k, n);
    for (int start = 0; start < count; ++start) {
        int current = start;
        int prev = nums[start];
        do {
            int next = (current + k) % n;
            swap(nums[next], prev);
            current = next;
        } while (start != current);
    }
}

int main(){
    vector<int> nums = { 1,2,3,4,5,6 };
    rotate(nums, 2);
    for(int i = 0; i < nums.size(); i++){
        cout << nums[i] << endl;
    }
    return 0;
}